package com.ruoyi.college.utils;

import net.sourceforge.pinyin4j.PinyinHelper;

import java.util.Objects;

/**
 * @author 明一G
 * @date 2023/3/28 16:02
 */
public class PinYin {
	public static String getPinYin(String name){
		if(!Objects.isNull(name)){
			String convert = "";
			for (int j = 0; j < name.length(); j++) {
				char word = name.charAt(j);
				String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
				if (pinyinArray != null) {
					convert += pinyinArray[0].charAt(0);
				} else {
					convert += word;
				}
			}
			return convert.toUpperCase();
		}
		return null;
	}
}
